﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiServer.Models;

namespace WebApiServer.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        [HttpGet]
        public IEnumerable<String> Get()
        {
            return HttpContext.User.Identities.Select(c => c.Name).ToArray();
           
        }

        //[HttpPost]
        //public async Task<ActionResult<TodoItem>> PostTodoItem(TodoItem todoItem)
        //{
        //    //_context.TodoItems.Add(todoItem);
        //    //await _context.SaveChangesAsync();

        //    ////return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
        //    //return CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem);
        //}
        [HttpGet("menus")]
        public ActionResult<object> Menus()
        {
            var output = new
            {
                data = new List<MenuItem>
                {
                    new MenuItem{ authName = "用户管理", id = 101, order = 1, path = "users", 
                        children = new List<MenuItem>
                        {
                            new MenuItem{ authName = "用户列表", id = 102, order = 1, path = "users"},
                            //new MenuItem{ authName = "用户管理", id = 1, order = 1, path = "users"}
                        } 
                    },
                    new MenuItem{ authName = "权限管理", id = 201, order = 2, path = "permissions",
                        children = new List<MenuItem>
                        {
                            new MenuItem{ authName = "用户列表", id = 202, order = 1, path = "permissions"},
                            //new MenuItem{ authName = "用户管理", id = 1, order = 1, path = "users"}
                        }
                    },
                    new MenuItem{ authName = "商品管理", id = 301, order = 3, path = "products",
                        children = new List<MenuItem>
                        {
                            new MenuItem{ authName = "任务列表", id = 302, order = 1, path = "todoitems"},
                            //new MenuItem{ authName = "用户管理", id = 1, order = 1, path = "users"}
                        }
                    },
                    new MenuItem{ authName = "订单管理", id = 401, order = 4, path = "orders",
                        children = new List<MenuItem>
                        {
                            new MenuItem{ authName = "用户列表", id = 402, order = 1, path = "orders"},
                            //new MenuItem{ authName = "用户管理", id = 1, order = 1, path = "users"}
                        }
                    },
                    new MenuItem{ authName = "数据统计", id = 501, order = 5, path = "statistics",
                        children = new List<MenuItem>
                        {
                            new MenuItem{ authName = "用户列表", id = 502, order = 1, path = "statistics"},
                            //new MenuItem{ authName = "用户管理", id = 1, order = 1, path = "users"}
                        }
                    },
                },
                meta = new
                {
                    msg = "菜单列表",
                    status = 200
                }
            };

            return output;
        }

    }
}